package com.dbsync.task;

import com.dbsync.core.SQLExecutor;
import org.slf4j.Logger;

import java.util.TimerTask;

/**
 * 数据库同步任务类
 */
public class Task extends TimerTask {
    // sql执行类
    private SQLExecutor executor;
    // 日志对象
    private Logger logger;

    public Task(SQLExecutor executor, Logger logger) {
        this.executor = executor;
        this.logger = logger;
    }

    @Override
    public void run() {
        try {
            executor.excute();
        }catch (Exception e){
            this.logger.error(e.getMessage());
            logger.info("*************************************同步操作任务"+(executor.getTargetIndex()+1)+"结束*************************************");
            throw new RuntimeException(e);
        }
    }
}
